﻿using System;
using System.Runtime.InteropServices;
using Microsoft.VisualStudio;
using Microsoft.VisualStudio.Project;
using Microsoft.VisualStudio.Shell.Interop;
using Microsoft.WowAddonStudio.Services;

namespace Microsoft.WowAddonStudio.Project
{
	/// <summary>
	/// An object that deals with user interaction via a GUI in the form a hierarchy: a parent node with zero or more child nodes, each of which
	/// can itself be a hierarchy.  
	/// </summary>
    [GuidAttribute(GuidStrings.WowXmlFileNode)]
    public class WowXmlFileNode : WowFileNode
    {
		/// <summary>
		/// Initializes a new instance of the <see cref="WowXmlFileNode"/> class.
		/// </summary>
		/// <param name="root">The root.</param>
		/// <param name="e">The e.</param>
        internal WowXmlFileNode(ProjectNode root, ProjectElement e)
            : base(root, e)
        {
        }

        protected override void DoDefaultAction()
        {
            var addonStudioSettings = (IAddonStudioSettings) this.GetService(typeof (IAddonStudioSettings));
            if (addonStudioSettings != null)
            {
                if (addonStudioSettings.OpenInEditor)
                {
                    // Open FrameXml in editor mode
                    IVsWindowFrame frame;
                    FileDocumentManager manager = this.GetDocumentManager() as FileDocumentManager;
                    manager.Open(false, false, VSConstants.LOGVIEWID_TextView, out frame, WindowFrameShowAction.Show);
                    return;
                }
            }

            base.DoDefaultAction();
        }

		/// <summary>
		/// Gets the index of the image.
		/// </summary>
		/// <value>The index of the image.</value>
        public override int ImageIndex
        {
            get
            {
                return (int)ProjectNode.ImageName.XMLFile;
            }
        }

    }
}
